package cn.fxl.service.impl;

import cn.fxl.ajax.AjaxResult;
import cn.fxl.domain.MoveUser;
import cn.fxl.domain.Movie;
import cn.fxl.mapper.MovieMapper;
import cn.fxl.mapper.MovieUserMapper;
import cn.fxl.service.IMovieUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MovieUserServiceImpl implements IMovieUserService {
    @Autowired
    private MovieUserMapper movieUserMapper;
    @Autowired
    private MovieMapper movieMapper;
    @Override
    public AjaxResult moveGetOne(Long id) {
        MoveUser one = movieUserMapper.moveGetOne(id);
        if(one==null){
            return new AjaxResult(false,"还没有购买过电影票");
        }
        if(one.getStatus()==1){
            return new AjaxResult(false,"电影票已经使用");
        }
        Movie movie = movieMapper.getOne(id);
        Date end_time = movie.getEnd_time();
        long time = end_time.getTime();
        Date date = new Date();
        long time1 = date.getTime();
        if(time1-time>0){
            return new AjaxResult(false,"票过期了");
        }else {
            one.setStatus(1);
            movieUserMapper.update(one);
            return new AjaxResult();
        }
    }

    @Override
    public void update(MoveUser moveUser) {
        movieUserMapper.update(moveUser);
    }

    @Override
    public void saveAdd(MoveUser moveUser) {
        movieUserMapper.saveAdd(moveUser);
    }
}
